﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[FDelete_Delete]
	(
	@Id INT,
	@table_type VARCHAR(50)	
	
	)
AS
BEGIN
	DECLARE @str_Where VARCHAR(1000)
	
	IF @table_type='Finance_RunningAccount'--收入
      BEGIN
      	
      	  delete Finance_RunningAccount  WHERE id=@Id
      END
	ELSE IF @table_type='Finance_Outlay'--支出
	  BEGIN
	  	
	  	  delete Finance_Outlay  WHERE id=@Id
	  END   
	  ELSE IF  @table_type='L_Reimbursement'--报销
	    BEGIN
	    	
	    	  delete L_Reimbursement  WHERE id=@Id
	    	  
	    	  DELETE FROM Finance_Outlay WHERE l_id=@Id and l_type='LR'
	    	  
	    	  DELETE FROM Assets WHERE l_id=@Id
	    	  
	    	  DELETE FROM L_Reimbursement_Item WHERE Pid=@Id
	    	  
	    END      
	    ELSE IF @table_type='L_Dealings'--公司往来
	     BEGIN
	     	   
	     	  delete L_Dealings  WHERE id=@Id
	     	  DELETE FROM Finance_Outlay WHERE l_id=@Id and l_type='LD'
	     	  
	     	  DELETE FROM Finance_RunningAccount WHERE l_id=@Id
	     	  
	     END  
	     else if @table_type='Loan'--借款
	     begin
			delete loan where id=@Id
			DELETE FROM Finance_Outlay WHERE  l_id=@Id and l_type='L'
	     end
	     ELSE 
	     	BEGIN
	     		RETURN
	     	END                   
END
